package xuyuanjun.paymenthandler.entities;

/**
 * 
 * @author Xu Yuanjun
 *
 */
public class Account {
	
	private Currency currency;
	private double balance;
	
	public Account(Currency currency, double balance) {
		this.currency = currency;
		this.balance = balance;
	}

	public synchronized double getBalance() {
		return balance;
	}

	public synchronized void setBalance(double balance) {
		this.balance = balance;
	}
	
	//return the balance info including currency code and balance if then account balance > 0
	public synchronized String getAccountBalanceInfo() {
		if (balance > 0) {
			StringBuilder s = new StringBuilder(currency.getCurrencyCode() + " " + balance);
			//append the info of exchange currency if the exchange currency is set
			if (currency.getExchangeRate() > 0 && !currency.getCurrencyCode().equals(currency.getExchangeCurrency())) {
				s.append("(" + currency.getExchangeCurrency() + " " + balance * currency.getExchangeRate() + ")");
			}
			return s.toString(); 
		}
		return null;
	}
}
